//
//  TPButton.m
//  Tripvi
//
//  Created by xiaowuxiaowu on 2017/5/12.
//  Copyright © 2017年 xiaowuxiaowu. All rights reserved.
//

#import "TPButton.h"

@implementation TPButton

-(void)tp_arrow{
    [self setImage:ImageNamed(@"Cell_right_arrow_withe") forState:UIControlStateNormal];
}


-(void)layoutSubviews{

    [super layoutSubviews];
    CGSize imgSize = self.imageView.image.size;
    
    switch (self.aligmentType) {
        
        case TPButtonAlignmentTypeDefalut:
        case TPButtonAlignmentTypeCenterRight:{
           
            CGFloat centerX= self.width/2 - imgSize.width/2;
            self.titleLabel.centerX = centerX;
            self.imageView.left = self.titleLabel.right + 5.0f;
        
        }
            break;
        case TPButtonAlignmentTypeCenterLeft:{
            
            CGFloat centerX= self.width/2 - imgSize.width/2;
            self.titleLabel.centerX = centerX;
            self.imageView.right = self.titleLabel.left - 5.0f;
        }
            
            break;
        case TPButtonAlignmentTypeLeft:{
        
            self.imageView.left = 5.0f;
            self.titleLabel.left = self.imageView.right + 5.0f;
        }
            
            break;
        case TPButtonAlignmentTypeRight:{
        
            self.titleLabel.left = 5.0f;
            self.imageView.left = self.titleLabel.right + 5.0f;
        }
            
            break;
        case TPButtonAlignmentTypeCenterUp:{
            
            
           self.imageView.centerX = self.width/2;
            
            self.titleLabel.textAlignment = NSTextAlignmentCenter;
            self.titleLabel.left = 0;
            self.titleLabel.width = self.width;
//            self.titleLabel.height = self.height - imgSize.height;
            self.imageView.centerY = self.height/2 - imgSize.height/2 - self.titleLabel.height/4;
            self.titleLabel.top = self.imageView.bottom + self.titleLabel.height/2;
            
//            DLog(@"imageView---%@----%@",NSStringFromCGRect(self.imageView.frame),NSStringFromCGRect(self.titleLabel.frame));
        }
            
            break;
      
        default:
            break;
    }
    
}

@end


@implementation TPCityButton
-(void)willMoveToSuperview:(UIView *)newSuperview{
    
    self.imageView.contentMode = UIViewContentModeScaleAspectFit;
    self.titleLabel.textAlignment = NSTextAlignmentRight;
    self.contentHorizontalAlignment = UIControlContentHorizontalAlignmentRight;
}
-(CGRect)imageRectForContentRect:(CGRect)contentRect{
    return CGRectMake(contentRect.size.width - 14, contentRect.origin.y+9, 9, 9);
}
-(CGRect)titleRectForContentRect:(CGRect)contentRect{
    //    DLog(@"titleRectForContentRect=%@",NSStringFromCGRect(contentRect));
    return CGRectMake(0.0, contentRect.origin.y, contentRect.size.width-14, contentRect.size.height);
}

@end


